package com.jinsi.controller.yrf;
import com.jinsi.pojo.SyUser;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * @author: 86185
 * @description: 根据" / "能直接访问登陆页面
 * @date 2022/9/16
 */

@Controller
@Slf4j
public class LoginPageController {
    /** 通过logger 添加日志*/
    private static Logger logger = LoggerFactory.getLogger(LoginPageController.class);

    /**
     * @Description: 登录是否有数据
     * @Date: 2022/10/27
     * @Param request:
     **/
    @RequestMapping("/")
    public String index(HttpServletRequest request) {

        HttpSession session = request.getSession();
        SyUser user = (SyUser) session.getAttribute("loginuser");
        System.out.println("/user为:"+user);
        if (user != null) {
            return  "redirect:/pages/index/index.html";
        }else {
            return "redirect:/login.html";
        }

    }

    @RequestMapping("/register/htl")
    public String regHtl() {
        log.info("进入注册页面");
        return "register";
    }


    /**
     * 日志测试（添加）
     */
    @GetMapping("/test1")
    public void test1() {
        System.out.println("6666");
        try {
            logger.info("this is a info message");
            int i=0;
            i=1/i;
        } catch (Exception e) {
            logger.error("attention, error!",e);
        }

    }

}
